<?php

namespace app\api\model;

use app\common\library\Token;
use app\common\model\BaseModel;
use think\facade\Db;

class Venue extends BaseModel
{
    // 表名
    protected $name = 'venue';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
    ];

    /**
     * 场馆列表
     */
    public static function venueList($requestData){
        $list = self::field('id,venue_name,venue_images,venue_price')->withCount('site')->where(['is_delete' => 1, 'status' => 1])->select();
        if($list){
            foreach ($list as $key => $value){
                $venue_images = explode(',', $value['venue_images']);
                $list[$key]['venue_images'] = $venue_images;
                $list[$key]['image_num'] = count($venue_images);
            }
        }
        return ['status' => 1, 'message' => '操作成功', 'result' => $list];
    }

    public function site(){
        return $this->hasMany('site', 'venue_id', 'id');
    }

}
